home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * tofish -
- * Create a fish-eye view of an environment map.
- *
- * Paul Haeberli - 1987
- */
- #include "texture.h"
-
- #define PI (3.1415926535)
- #define EPSILON (0.00001)
-
- TEXTURE *tm;
- int doreflect;
- int size, samples;
-
- main(argc,argv)
- int argc;
- char **argv;
- {
- float vr, vg, vb;
- float tr, tg, tb;
- int x, y, i;
- IMAGE *image;
- vect pos, c;
- float angle;
- short *rbuf, *gbuf, *bbuf;
-
- if(argc<6) {
- fprintf(stderr,"usage: tofish size samples file.env file.rgb angle\n");
- exit(1);
- }
- size = atoi(argv[1]);
- samples = atoi(argv[2]);
- tm = tmopen(argv[3]);
- angle = atof(argv[5]);
- if(!tm) {
- printf("can't open environment map.\n");
- exit(1);
- }
- rbuf = (short *)malloc(size*sizeof(short));
- gbuf = (short *)malloc(size*sizeof(short));
- bbuf = (short *)malloc(size*sizeof(short));
- image = iopen(argv[4],"w",RLE(1),3,size,size,3);
- for(y=0; y<size; y++) {
- for(x=0; x<size; x++) {
- tr = tg = tb = 0.0;
- for(i=0; i<samples; i++) {
- if(samples>1) {
- pos.x = (x+frand())/size-0.5;
- pos.y = (y+frand())/size-0.5;
- pos.z = 0;
- } else {
- pos.x = (float)x/size-0.5;
- pos.y = (float)y/size-0.5;
- pos.z = 0.0;
- }
- tofish(&pos,angle,&c);
- tr += c.x;
- tg += c.y;
- tb += c.z;
- }
- rbuf[x] = 255*tr/samples;
- gbuf[x] = 255*tg/samples;
- bbuf[x] = 255*tb/samples;
- }
- putrow(image,rbuf,y,0);
- putrow(image,gbuf,y,1);
- putrow(image,bbuf,y,2);
- tpercentdone(100.0*y/(size-1));
- }
- iclose(image);
- }
-
- tofish(p,angle,c)
- vect *p, *c;
- float angle;
- {
- vect e, v, r;
- float away, mag;
- float radmult, z;
-
- mag = sqrt(p->x*p->x+p->y*p->y);
- if(mag>0.5) {
- c->x = 1.0;
- c->y = 1.0;
- c->z = 1.0;
- return;
- } else if(mag>EPSILON) {
- away = (PI*mag*angle)/180.0;
- radmult = sin(away);
- v.x = (radmult*p->x)/mag;
- v.y = (radmult*p->y)/mag;
- v.z = cos(away);
- } else {
- v.x = 0.0;
- v.y = 0.0;
- v.z = 1.0;
- }
- v.z = -v.z;
- lookx(&v);
- envsample(tm,&v,c);
- }
-
- lookx(v)
- vect *v;
- {
- float temp;
-
- temp = v->z; /* to make us look down the x axis */
- v->z = v->y;
- v->y = -v->x;
- v->x = temp;
- }
-